//测试自己实现的smart_ptr

#include "smart_ptr.h"
#include <iostream>
#include<string>

//using std::cout; 这一句代码的作用是引入 std 命名空间中的 cout 对象，
//使得在后续代码中可以直接使用 cout 而不必每次都写 std::cout。
using std::cout;
using std::endl;
using std::string;

struct MyStruct
{
	MyStruct() = default;
	MyStruct(int a, int b) :a(a), b(b) {}
	int a;
	int b;
};

int main()
{
	MyStruct *s = new MyStruct();
	s->a = 10;
	s->b = 20;

	smart_ptr<MyStruct> sp(s);

	cout << sp->a << endl;
	cout << sp->b << endl;
	cout << (*sp).a << endl;

	auto sp2 = make_smart<MyStruct>(100, 200);
	cout << sp2->a << endl;
	cout << sp2->b << endl;

	cout<<"---------------------"<<endl;
	smart_ptr<string> msp1(new string("abc"));
	smart_ptr<string> msp2=msp1;
	smart_ptr<string> msp3=msp1;
	smart_ptr<string> msp4=msp1;
	msp3.reset();
	cout<<"msp1.use_count():"<<msp1.use_count()<<endl;
	cout<<"msp3.use_count():"<<msp3.use_count()<<endl;
	msp4.reset(new string());
	cout<<"msp1.use_count():"<<msp1.use_count()<<endl;
	cout<<"msp4.use_count():"<<msp4.use_count()<<endl;	
	cout<<"---------------------"<<endl;




	return 0;
}
